<template>
  <div>
    <div v-if="news.length">
      <div class="wrapper" v-for="(item, index) in news" :key="item.id">
        <div class="user">
          <p v-if="item.status == '待处理'" class="deal1">待处理</p>
          <p v-else class="deal2">{{ item.status }}</p>
          <!-- 点击按钮让item.dealstate = false，效果：待处理变成已处理，按钮消失 -->
          <div class="button" v-if="item.status == '待处理'">
            <el-button size="medium" round :plain="true" @click="refuse(item)"
              >拒绝</el-button
            >
            <el-button
              size="medium"
              round
              :plain="true"
              type="success"
              @click="agree(item)"
              >同意</el-button
            >
          </div>
        </div>
        <input :id="index" class="exp" type="checkbox" />
        <div class="text">
          <label class="btn" :for="index"></label>
          <!-- 这里要改成用户信息页面（看他人） -->
          <span class="name" @click="$router.push('/personal')">{{
            item.rentname
          }}</span
          >:{{ item.note }}
        </div>
      </div>
    </div>
    <div v-else><nodata></nodata></div>
  </div>
</template>


<script>
import request from "@/utils/request";
import nodata from "../../components/nodata.vue";
export default {
  components: {
    nodata,
  },
  data() {
    return {
      Index: 1,
      isActive: 1,
      //获取localStorage中保存的后台返回的用户信息
      user: localStorage.getItem("user")
        ? JSON.parse(localStorage.getItem("user"))
        : {},
      news: [],
    };
  },
  created() {
    this.listWanted();
  },
  methods: {
    async listWanted() {
      await request.get("/wanted/owner/" + this.user.id).then((res) => {
        if (res.code === 200) {
          this.news = res.data;
        } else {
          this.$notify.error(res.msg);
        }
      });
      for (let i = 0; i < this.news.length; i++) {
        const userRes = await request.get(
          `/user/${this.news[i].rentId}`
        );
        if (userRes.code === 200) {
          this.$set(this.news[i], "rentname", userRes.data.nikeName);
        }
      }
    },
    refuse(wanted) {
      request.put("/wanted/disagree",wanted).then((res) => {
        if (res.code === 200) {
          this.$notify.success("拒绝成功");
          this.listWanted();
        } else {
          this.$notify.error(res.msg);
        }
      });
    },
    agree(wanted) {
      console.log(wanted)
      request.put("/wanted/agree",wanted).then((res) => {
        if (res.code === 200) {
          this.$notify.success("同意成功");
          this.listWanted();
        } else {
          this.$notify.error(res.msg);
        }
      });
    },
  },
};
</script>


<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.wrapper {
  position: relative;
  display: flex;
  margin: 5px auto;
  width: 650px;
  overflow: hidden;
  /* border-radius: 8px; */
  padding: 15px;
  /* box-shadow: 5px 4px 14px #bebebe, -20px -20px 60px #ffffff; */
  border-bottom: 1px dashed black;
}
.user {
  position: absolute;
  width: 200px;
  text-align: left;
  margin-top: -25px;
  margin-left: 50px;
}
.avatar {
  margin-left: -47px;
  margin-top: 20px;
}
.deal1 {
  color: red;
  font-size: 17px;
  font-weight: 600;
  font-family: "Microsoft YaHei";
  margin-left: -45px;
  margin-top: 28px;
}
.deal2 {
  color: gray;
  font-size: 17px;
  font-weight: 600;
  font-family: "Microsoft YaHei";
  margin-left: -45px;
  margin-top: 28px;
}
.button {
  margin-left: 426px;
  margin-top: -47px;
  position: relative;
}
.el-button--default {
  position: absolute;
}
.el-button--success {
  position: absolute;
  margin-left: 83px;
}
.name {
  cursor: pointer;
  color: black;
  font-size: 18px;
  font-weight: 600;
}
.name:hover {
  color: cornflowerblue;
}
/* 多行文本超出省略 */
.text {
  font-size: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: justify;
  /* display: flex; */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  position: relative;
  margin-top: 55px;
}
.text::before {
  content: "";
  height: calc(100% - 24px);
  float: right;
}
.text::after {
  content: "";
  width: 999vw;
  height: 999vw;
  position: absolute;
  box-shadow: inset calc(100px - 999vw) calc(30px - 999vw) 0 0 #fff;
  margin-left: -100px;
}
.btn {
  float: right;
  clear: both;
  margin-left: 10px;
  font-size: 16px;
  padding: 0 8px;
  background: #1c92d2;
  line-height: 24px;
  border-radius: 4px;
  color: #fff;
  cursor: pointer;
  /* margin-top: -30px; */
}
.btn::before {
  content: "展开";
}
.exp {
  display: none;
}
.exp:checked + .text {
  -webkit-line-clamp: 999;
}
.exp:checked + .text::after {
  visibility: hidden;
}
.exp:checked + .text .btn::before {
  content: "收起";
}
</style>
